package com.ferry.common.util.concurrent;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/**
 * Created by daiyong
 */
public class Updaters {


	private Updaters() {

	}

	public static <U, W> AtomicReferenceFieldUpdater<U, W> newAtomicReferenceFieldUpdater(
			Class<U> tClass, Class<W> vClass, String fieldName) {
		try {
			if (UnsafeUtil.hasUnsafe()) {
				return new UnsafeAtomicReferenceFieldUpdater<>(UnsafeUtil.getUnsafeAccessor().getUnsafe(), tClass, fieldName);
			} else {
				return AtomicReferenceFieldUpdater.newUpdater(tClass, vClass, fieldName);
			}
		} catch (Throwable t) {
			return AtomicReferenceFieldUpdater.newUpdater(tClass, vClass, fieldName);
		}
	}



}
